﻿using System;
using System.Collections.Generic;
using Luna.Data.Common;
using Luna.Data.Crm;

namespace Luna.Data.Test.Crm
{
    public class CrmDataProviderTest : EntityWithReferenceTest<ICrmDataProvider, IEntityData>
    {
        public CrmDataProviderTest(string contextName)
            : base(contextName)
        {
        }

        public override Action<IReferenceData> Delete
        {
            get { return Service.EntityDelete; }
        }

        public override Predicate<IEntityData> DeletePredicate
        {
            get { return x => x.Name.StartsWith(DataManager.Generator.SeedString); }
        }

        public override Func<IReferenceData, IEntityData> Get
        {
            get { return Service.EntityGet; }
        }

        public override Func<IEnumerable<IEntityData>> GetAll
        {
            get { return Service.EntitiesGetAll; }
        }

        public override Action<IEntityData> Save
        {
            get { return Service.EntitySave; }
        }

        protected override bool AreSame(IEntityData data1, IEntityData data2)
        {
            return DataManager.AreSame(data1, data2);
        }

        protected override IEntityData Create()
        {
            var entity = Context.Get<IEntityData>();
            DataManager.Load(entity);
            return entity;
        }
    }
}